<template>
  <div>
    <el-form :inline="true" label-width="80px">
      <el-form-item label="任务名称">
        <el-input
          v-model="queryParams.jobName"
          placeholder="任务名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="方法名称">
        <el-input
          v-model="queryParams.invokeTarget"
          placeholder="方法名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="状态">
        <el-select @keyup.enter.native="handleQuery" v-model="queryParams.status" placeholder="不限"
                   clearable
                   size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleClean" v-hasPermi="['monitor:jobLog:clean']">清空</el-button>
      </el-form-item>


    </el-form>

    <el-table v-loading="loading" :data="postList">
      <el-table-column label="任务名称" align="center" prop="jobName" :show-tooltip-when-overflow="true"/>
      <el-table-column label="任务组名" align="center" prop="jobGroup" :show-tooltip-when-overflow="true"/>
      <el-table-column label="方法名称" align="center" prop="invokeTarget" :show-tooltip-when-overflow="true"/>
      <el-table-column label="方法参数" align="center" prop="methodParams" :show-tooltip-when-overflow="true"/>
      <el-table-column label="日志信息" align="center" prop="jobMessage" :show-tooltip-when-overflow="true"/>
      <el-table-column label="异常信息" align="center" prop="exceptionInfo" :show-tooltip-when-overflow="true"/>
      <el-table-column label="任务状态" align="center" prop="status" :formatter="typeFormat"/>
      <el-table-column label="创建时间" align="center" prop="createTime" :show-tooltip-when-overflow="true"/>


      <el-table-column label="操作" align="center" width="300">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.row)"
            v-hasPermi="['monitor:jobLog:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>

</template>

<script>
  import {list,remove,clean} from "@/api/monitor/joblog";

  export default {
    data() {
      return {
        runLoading: undefined,
        row: undefined,
        title: '',
        open: false,
        addLoading: false,
        loading: false,
        postList: [],
        statusOptions: [{dictValue:'0',dictLabel:'正常'},{dictValue:'1',dictLabel:'失败'}],
        current: 'index',
        tabs: [
          {index: 'index', name: ''}, {'index': 'obtain', name: '获取列表'},
        ],
        total: 0,
        loadingInstance: undefined,
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          jobName: undefined,
          invokeTarget: undefined,
          status: undefined
        }
      }
    },
    created() {
      this.getList();
    },
    methods: {
      getList() {
        this.loading = true;
        list(this.queryDateRange(this.queryParams, this.daterange)).then(response => {
          this.postList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      typeFormat(row, column) {
        let option;
        if (column.property === 'status') {
          option = this.statusOptions;
        }
        return this.selectDictLabel(option, row[column.property]);
      },
      handleDelete(row) {
        let _this = this;
        this.$confirm(`确定要删除任务名称为[${row.jobName}],任务组名称为[${row.jobGroup}]的日志记录?`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          remove(row.jobLogId).then(response => {
            _this.msgSuccess("删除成功");
            _this.getList();
          });
        }).catch(function (e) {
          console.log(e);
        });
      },
      handleClean(){
        let _this = this;
        this.$confirm(`确定要清空所有日志记录?`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          clean().then(response => {
            _this.msgSuccess("清空成功");
            _this.getList();
          });
        }).catch(function (e) {
          console.log(e);
        });
      }
    }
  }
</script>

<style>

</style>
